<?php
class Helper {
    
    /**
     * 跳转
     * --- 若无特别需求,请勿修改此函数,谢谢 ---
     * @param $strUrl 要跳转到的链接
     * @param $strMsg 跳转前的提示信息
     */
    public static function jsLoadTo($strUrl = '/', $strMsg = '') {
        if ('/' == $strUrl) {
            $strUrl = HTTP_URL;
        }
        $strAlert = !empty($strMsg) ? 'alert("' . $strMsg . '");' : '';
        $strJs = <<<JS
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script type="text/javascript">
{$strAlert}
window.top.location.href = "{$strUrl}";
</script>
</body>
</html>
JS;
        die($strJs);
    }
    
    /**
     * 加载模型,默认单例
     * --- 若无特别需求,请勿修改此函数,谢谢 ---
     * @param $strName 模型名称
     * @param $blnSingle 是否用单例模式
     */
    public static function loadModel($strName, $blnSingle = true) {
        static $arrSingleModels = array();
        $objRe = null;
        if (!empty($strName)) {
            $strKey = md5($strName);
            if ($blnSingle) {
                if (isset($arrSingleModels[$strKey])) {
                    $objRe = $arrSingleModels[$strKey];
                }
            }
            if (null === $objRe || empty($objRe) || false === $objRe) {
                $strClass = 'm_' . $strName;
                if (class_exists($strClass)) {
                    $objRe = new $strClass;
                }
            }
            if ($blnSingle && $objRe) {
                $arrSingleModels[$strKey] = $objRe;
            }
        }
        return $objRe;
    }
    
}